﻿using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Threading;
using System.Security.Cryptography;
using System.IO.Compression;

namespace SpyTxT
{
    class PackManger
    {

        public string InitLogin(string user, string city)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            //command
            xtw.WriteStartElement("command");
            xtw.WriteString("2");
            xtw.WriteEndElement();


            //command
            xtw.WriteStartElement("data");

            xtw.WriteStartElement("ver");
            xtw.WriteString("1071");
            xtw.WriteEndElement();

            xtw.WriteStartElement("user");
            xtw.WriteString(user);
            xtw.WriteEndElement();

            xtw.WriteStartElement("city");
            xtw.WriteString(city);
            xtw.WriteEndElement();

            xtw.WriteEndElement();


            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string IniLoginInTo(string user,string pass)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            //command
            xtw.WriteStartElement("command");
            xtw.WriteString("13");
            xtw.WriteEndElement();


            //command
            xtw.WriteStartElement("data");

            xtw.WriteStartElement("login");

            xtw.WriteStartElement("loginid");
            xtw.WriteString(user);
            xtw.WriteEndElement();

            xtw.WriteStartElement("password");
            xtw.WriteString(pass);
            xtw.WriteEndElement();

            xtw.WriteStartElement("autoLogin");
            xtw.WriteString("true");
            xtw.WriteEndElement();

            xtw.WriteStartElement("loginType");
            xtw.WriteString("1");
            xtw.WriteEndElement();

            xtw.WriteStartElement("client");
            xtw.WriteString("KALA");
            xtw.WriteEndElement();

            xtw.WriteStartElement("ver");
            xtw.WriteString("1071");
            xtw.WriteEndElement();

            xtw.WriteStartElement("machineno");
            xtw.WriteString("9RA4VRAS#005056C00001");
            xtw.WriteEndElement();

            xtw.WriteStartElement("otherProgram");
            xtw.WriteEndElement();


            xtw.WriteEndElement();

            xtw.WriteEndElement();


            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string InitLogin2()
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            xtw.WriteStartElement("command");
            xtw.WriteString("31");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");
            xtw.WriteString("374786");
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string InitLoginCmd10(string ticket)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            xtw.WriteStartElement("command");
            xtw.WriteString("10");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");

            xtw.WriteStartElement("login");

            xtw.WriteStartElement("ver");
            xtw.WriteString("1071");
            xtw.WriteEndElement();

            xtw.WriteStartElement("loginid");
            xtw.WriteString(ticket);
            xtw.WriteEndElement();

            xtw.WriteStartElement("userid");
            xtw.WriteString("374786");
            xtw.WriteEndElement();

            xtw.WriteStartElement("password");
            xtw.WriteString("123456");
            xtw.WriteEndElement();

            xtw.WriteStartElement("machineno");
            xtw.WriteString("9RA4VRAS#005056C00008");
            xtw.WriteEndElement();

            xtw.WriteStartElement("gzip");
            xtw.WriteString("1");
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string InitLoginCmd93()
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            xtw.WriteStartElement("command");
            xtw.WriteString("93");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");
            xtw.WriteString("startup");
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string InitLoginCmd23()
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            xtw.WriteStartElement("command");
            xtw.WriteString("23");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");
            xtw.WriteString("tianxia");
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string InitLoginCmd60()
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            xtw.WriteStartElement("command");
            xtw.WriteString("60");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");
            xtw.WriteString("ALL");
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string InitLoginCmd41(string cityname)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            xtw.WriteStartElement("command");
            xtw.WriteString("41");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");
            xtw.WriteString(cityname);
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string InitLoginCmd42(string cityname)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            xtw.WriteStartElement("command");
            xtw.WriteString("42");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");
            xtw.WriteString(cityname);
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string InitLoginCmd34(string ticket)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            xtw.WriteStartElement("command");
            xtw.WriteString("34");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");
            xtw.WriteString(ticket);
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string InitLoginCmd99(string cityname)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            xtw.WriteStartElement("command");
            xtw.WriteString("99");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");

            xtw.WriteStartElement("st");
            xtw.WriteString("app");
            xtw.WriteEndElement();

            xtw.WriteStartElement("ct");
            xtw.WriteString(cityname);
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string InitLoginCmd94(string ticket)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            xtw.WriteStartElement("command");
            xtw.WriteString("94");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");

            xtw.WriteStartElement("tcp");

            xtw.WriteStartElement("loginid");
            xtw.WriteString(ticket);
            xtw.WriteEndElement();

            xtw.WriteStartElement("crcount");
            xtw.WriteString("1");
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
        public string InitLoginCmd27(string cityname)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;
            //xtw.WriteStartDocument(false);

            xtw.WriteStartElement("commblock");

            xtw.WriteStartElement("command");
            xtw.WriteString("27");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");
            xtw.WriteString(cityname);
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;
        }
 
        public string IniiRequestCity(string cityname)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;

            xtw.WriteStartElement("commblock");

            //command
            xtw.WriteStartElement("command");
            xtw.WriteString("27");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");
            xtw.WriteString(cityname);
            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;

        }
        public string IniiRequestCityLogin(string cityname)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.None;

            xtw.WriteStartElement("commblock");

            //command
            xtw.WriteStartElement("command");
            xtw.WriteString("21");
            xtw.WriteEndElement();

            xtw.WriteStartElement("data");
            
            xtw.WriteStartElement("phwhere");

            xtw.WriteStartElement("id");
            xtw.WriteString("0");
            xtw.WriteEndElement();

            xtw.WriteStartElement("ownerid");
            xtw.WriteString("0");
            xtw.WriteEndElement();


            xtw.WriteStartElement("mark");
            xtw.WriteString("1");
            xtw.WriteEndElement();

            xtw.WriteStartElement("types");
            xtw.WriteString("0");
            xtw.WriteEndElement();

            xtw.WriteStartElement("fromcitys");
            xtw.WriteString(cityname);
            xtw.WriteEndElement();

            xtw.WriteStartElement("fromlevel");
            xtw.WriteString("1");
            xtw.WriteEndElement();

            xtw.WriteStartElement("keylogic");
            xtw.WriteString("0");
            xtw.WriteEndElement();

            xtw.WriteStartElement("userid");
            xtw.WriteString("0");
            xtw.WriteEndElement();

            xtw.WriteStartElement("filteroverlap");
            xtw.WriteString("0");
            xtw.WriteEndElement();

            xtw.WriteStartElement("collectinfo");
            xtw.WriteString("0");
            xtw.WriteEndElement();


            

            xtw.WriteEndElement();


            xtw.WriteEndElement();

            xtw.WriteEndElement();

            string result = sw.ToString();
            result += "<end/>\r\n";

            return result;

        }
        public string InitHttpRequest(string refurl)
        {
            string httprequest ="";
            //httprequest += "GET /nava/jsp/about/logo.jsp HTTP/1.1";
            httprequest += "GET ";
            httprequest += refurl;
            httprequest += " HTTP/1.1\r\n";
            httprequest += "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-shockwave-flash, */*\r\n";
            httprequest += "Accept-Language: zh-cn\r\n";
            httprequest += "Accept-Encoding: gzip, deflate\r\n";
            httprequest += "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 551; GTB6; TencentTraveler 4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ;  Embedded Web Browser from: http://bsalsa.com/; Brwn Embedded Web Browser from: http://bsalsa.com/; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)\r\n";
            httprequest += "Host: tx1.tianxia800.com\r\n";
            httprequest += "Connection: Keep-Alive\r\n\r\n";

            return httprequest;
        }

        public string InitHttpRequestbyTicket(string refurl)
        {
            string httprequest = "";
            httprequest += "GET ";
            httprequest += refurl;//nava/update.action?ticket=103dd1d5904d534767c2a8b141a38f2d&ver=1071&type=0 
            httprequest += " HTTP/1.0\r\n";
            httprequest += "Host: web2.tianxia800.com\r\n";
            httprequest += "User-Agent: Mozilla/4.0 (compatible; Synapse)\r\n\r\n";

            return httprequest;
        }
       
    }
}
